package com.briup.cms.exception;

import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Administrator
 * @version 1.0
 * @Description
 * @date 2021/7/17 19:23
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler({Exception.class})
    public Message handler(Exception exception) {
        exception.printStackTrace();
        if (exception instanceof CustomerException) {
            CustomerException customerException = (CustomerException)exception;
            if (customerException.getMessageStatus() != null)
                return MessageUtil.error(customerException.getMessageStatus());
        }
        return MessageUtil.error("后台接口异常！"+ exception.getMessage());
    }
}
